﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="~/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="~/layuimini/css/public.css" media="all">
    <style>
        .box {
            text-align: center;
        }
    </style>
</head>
<body style="background-color:#C0C0C0">
    <div class="box">
        <div id="showStaffInfo"></div>
        <a class="layui-btn  layui-btn-normal" id="bindBtn">提交绑定</a>
    </div>

    <script src="~/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script>
        layui.use(function () {
            var transfer = layui.transfer,
                $ = layui.jquery;//引入jQuery

            var roleId = window.location.search.substr(4);//获取父级传递的角色id
            //发起请求获取数据
            $.ajax({
                url: '/Admin/RoleInfo/GetUserInfoOptions',
                type: 'get',
                data: {
                    roleId: roleId
                },
                success: function (res) {
                    console.log("获取为绑定的数据",res);
                    if (res.code == 200) {
                        // 渲染
                        transfer.render({
                            elem: '#showStaffInfo',
                            data: res.data.options,//显示左边数据
                            title: ['未绑定的用户', '已经绑定的用户'],
                            value: res.data.userIds,//选中数据
                            showSearch: true,//显示搜索框
                            parseData: function (result) {
                                console.log("parseData",result);
                                return {
                                    "value": result.id, // 数据值
                                    "title": result.staffName, // 数据标题
                                }
                            },
                            id: "staffInfoList"
                        });                       
                    } else {
                        layer.msg(res.msg);
                    }
                }
            });


           @* // 数据
            var data = [
                { "id": "1", "userName": "李白" },
                { "id": "2", "userName": "杜甫" },
                { "id": "3", "userName": "苏轼" },
                { "id": "4", "userName": "李清照" },
                { "id": "5", "userName": "鲁迅"},
                { "id": "6", "userName": "巴金" },
                { "id": "7", "userName": "冰心" },
                { "id": "8", "userName": "矛盾" },
                { "id": "9", "userName": "贤心" }
            ];
            // 渲染
            transfer.render({
                elem: '#showUser',
                data: data,
                title: ['未绑定的用户', '已经绑定的用户'],
                value: ['1', '2'],
                showSearch: true,
                parseData: function (res) {
                    return {
                        "value": res.id, // 数据值
                        "title": res.userName, // 数据标题
                        //"disabled": res.disabled,  // 是否禁用
                        //"checked": res.checked // 是否选中
                    }
                },
                id:"userList"
            });*@


            //按钮的点击事件
            $("#bindBtn").click(function (res) {
                var getData = transfer.getData('staffInfoList'); // 获取右侧数据
                //layer.alert(JSON.stringify(getData));
                //根据getDate遍历出userids
                var userIds = [];
                for (var i = 0; i < getData.length; i++) {
                    var userId = getData[i].value;
                    userIds.push(userId)
                }
                //发起ajax请求
                $.ajax({
                    url: '/Admin/RoleInfo/BindStaffInfo',
                    type: 'post',
                    data: {
                        userIds: userIds,
                        roleId: roleId
                    },
                    success: function (res) {
                        layer.msg(res.msg);

                        //执行搜索重载
                        parent.table.reload('currentTableId', {
                            page: {
                                curr: 1
                            }
                            , where: {

                            }
                        }, 'data');

                    }
                });


            });


        });
    </script>
</body>
</html>
